import {useState,useEffect} from 'react'
import HTTP from '../../services/api'
import workerApi from '../../api/worker.api'
import SelfTable from '../../tools/selfTable'
import { message,Avatar,Button } from 'antd'
const columns = [
    {
        title: '头像',
        dataIndex: 'header_img',
        render:text=><Avatar size={98} src={text} />
    },
    {
        title: '姓名',
        dataIndex: 'username',
    },
    {
        title: '昵称',
        dataIndex: 'nickname',
    },
    {
        title: '性别',
        dataIndex: 'sex',
    },
    {
        title: '岗位',
        dataIndex: 'position',
    },
    {
        title: '联系方式',
        dataIndex: 'phone',
        // render:text=><p>{text.replace(/^\d{3}\d{4}\d{4}$/g,"$1 $3")}</p>
    },
    {
        title: '年龄',
        dataIndex: 'age',
    },
    {
        title: '入职时间',
        dataIndex: 'createdAt',
    },
    {
        title: '操作',
        dataIndex: 'active',
        render:(text,row)=><>
                            <Button type="primary">查看工作人员的信息</Button>
                            <Button type="primary" danger>删除该工作人员</Button>
                           </>
    }
]
export default function WorkerInfo(props){

    let [workinfo,setWorkinfo] = useState([])

    async function getAllWorkInfo(){
        let result = await HTTP({method:'get'},workerApi.getAllWorkerInfo,{type:'worker'})
        try{
            if(result.status){
                setWorkinfo(result.info)
                message.success(result.msg)
            }else{
                message.error(result.msg)
            }
        }catch(error){
            message.error('服务器异常')
        }
        console.log(result)
        setWorkinfo(result.info)
    }
    useEffect(()=>{
        getAllWorkInfo()
    },[])
    return (
        <>
            <h1>这是学生的页面</h1>
            <SelfTable dataSource={workinfo} columns={columns}  keyid = 'work_id' />
        </>
    )
}